
//Copyright 1997-2009 Syrinx Development, Inc.
//This file is part of the Syrinx Web Application Framework (SWAF).
// == BEGIN LICENSE ==
//
// Licensed under the terms of any of the following licenses at your
// choice:
//
//  - GNU General Public License Version 3 or later (the "GPL")
//    http://www.gnu.org/licenses/gpl.html
//
//  - GNU Lesser General Public License Version 3 or later (the "LGPL")
//    http://www.gnu.org/licenses/lgpl.html
//
//  - Mozilla Public License Version 1.1 or later (the "MPL")
//    http://www.mozilla.org/MPL/MPL-1.1.html
//
// == END LICENSE ==
using System;
using System.Collections;
using System.Text;
using System.Diagnostics;
using System.Web;
using System.Web.UI.WebControls;

using Swaf;
using Swaf.BizObj;
using Swaf.BizRule;
using Swaf.Gui;
using Swaf.Security;
using UserLogin.Gui;

namespace UserManagement.Gui
{
    /// <summary>
    /// 
    /// </summary>
    /// <param name="company"></param>
	public delegate void CompanyManagementHandler(IBizObj company);
    /// <summary>
    /// 
    /// </summary>
	public class CompanyManagementBizProc :  Swaf.Gui.BaseBusinessProcess
	{
		public CompanyManagementBizProc(ActiveBizProc procState)
			: base(procState)
		{
		}

		protected override void setupRuleNames()
		{
			m_getBizObjListRule = "getChildCompanies";
			m_getBizObjDetailsRule = "getCompany";
			m_updateBizObjRule = "updateCompany";
		}

		public override IBizObj createNewBizObj()
		{
			IBizObj cmp = App.bizObjMgr.create("Company");
			cmp.put("id", new Swaf.BGuid.Guid());
			cmp.put("parentId", CurrentBizObj.get("id"));
			return cmp;
		}
		protected override Privileges CurrentEditPrivilege
		{
			get { return CurrentPrincipal.getPrivilege("AppFunctions.SetupCompany"); }
		}

		protected override object[] getBizObjListRuleParameters(object parentId, IBizObj filterSort)
		{
			return new object[] { parentId==null ? ActiveCompanyId : parentId, true };
		}

		//void companyListDisplay_BizObjSelected(object source, IBizObj selectedBizObj, string info)
		//{
		//    if (selectedBizObj != null)
		//        base.CurrentUser.put("activeCompanyId", selectedBizObj.get("id"));
		//}
		///// <summary>
		///// 
		///// </summary>
		//public override void initiateDataRetrieval(ParentBizProcInfo parent)
		//{
		//    base.m_rules= App.ruleMgr.execute(m_baseRule, null, null, new object[] { CurrentCompanyId, true });
		//}

		//public void initiateDataRetrieval(IBizObj criteria)
		//{
		//    base.m_filterSortCriteria = criteria;
		//    if (criteria != null)
		//        base.m_rules = App.ruleMgr.execute("getCompanySearchResult", null, null, new object[] { criteria,false });
		//}
		///// <summary>
		///// 
		///// </summary>
		//public override void completeDataRetrieval()
		//{
		//    setUserPreferences();
		//    base.completeDataRetrieval();
		//}

		//public override void addNewBizObj()
		//{
		//    IResults rc = App.ruleMgr.execute(m_addNewBizObjRule, "New Company"
		//        , base.SelectedBizObj != null ? base.SelectedBizObj.get("id") as Swaf.BGuid.Guid : ActiveCompanyId
		//        , null, null, null, null);
		//    if (rc.ExceptionInfo != null)
		//        OnBizProcException(this, "addCompany", rc.ExceptionInfo);
		//    else
		//    {
		//        initiateDataRetrieval((ParentBizProcInfo)null);
		//        completeDataRetrieval();
		//    }
		//}
		//public event   BizObjBizProcEvent PreSearch;
		//public void startSearch()
		//{
		//    clearSessionBizObjList();
		//    IBizObj criteria = calcFilterSortOptions();
		//    if (PreSearch != null)
		//        PreSearch(this, criteria);

		//    initiateDataRetrieval(criteria);
		//    completeDataRetrieval();
		//}
		

		//public override IBizObj getBizObjDetails(IBizObj details)
		//{
		//    details = base.getBizObjDetails(details);
		//    if (details != null)
		//        CurrentUser.put("activeCompanyId", details.get("id"));
		//    return details;
		//}
		//protected override void setupActions()
		//{
		//    base.setupActions();
		//    base.m_editPriv = SecurityPriv;
		//    Actions.addAction(new GenericAction("StartSearch", true, startSearch, this));
		//}
        

		//protected void setUserPreferences()
		//{
		//    //call the bizRule to update user preferences
		//    IResults rc = App.ruleMgr.execute("getUserPreferences",
		//        (Swaf.BGuid.Guid)CurrentUser.get("id"),
		//        ActiveCompanyId);
		//    if (rc.ExceptionInfo != null)
		//        throw rc.ExceptionInfo;
		//    App.sessionData.put("userPreferences", rc.CallResults as IBizObj);
		//}

		//protected override void updateEditPriv(){base.m_inEditMode = SecurityPriv >= Privileges.Edit;}
		////protected Privileges SecurityPriv{get { return CurrentPrincipal.getPrivilege("AppFunctions.ManageUsers"); }}
		//protected Privileges SecurityPriv { get { return CurrentPrincipal.getPrivilege("AppFunctions.SetupCompany"); } }

	}
}
